import org.junit.Assert;
import org.junit.Test;
import org.tw.twu.cw.SimpleDotCom;

import static junit.framework.Assert.*;

/**
 * Created with IntelliJ IDEA.
 * User: abaluses
 * Date: 24/06/2013
 * Time: 16:48
 * To change this template use File | Settings | File Templates.
 */

public class SimpleDotComTest {


    @Test
    public void testItCreatesObject() throws Exception {
        SimpleDotCom simpleDotCom = new SimpleDotCom();
        assertTrue(simpleDotCom instanceof SimpleDotCom);
    }

    @Test
    public void testItStoresLocation() {
        SimpleDotCom simpleDotCom = new SimpleDotCom();
        simpleDotCom.location = new int[]{1, 2, 3};
        Assert.assertArrayEquals(simpleDotCom.location, new int[]{1, 2, 3});
    }

    @Test
    public void testIfLocationIsSet() {
        int [] locations = {1,2,3};
        SimpleDotCom simpleDotCom = new SimpleDotCom();
        simpleDotCom.setLocation (locations);
        Assert.assertArrayEquals(simpleDotCom.location, locations);

    }

    @Test
    public void testIfHitWhenTrueHit() {
       SimpleDotCom simpleDotCom = new SimpleDotCom();
       simpleDotCom.setLocation(new int[]{1, 2, 3});
       String guess = "2";
       assertEquals("Hit",simpleDotCom.verifyHit(guess));
    }

    @Test
    public void testIfHitWhenNotHit() {
        SimpleDotCom simpleDotCom = new SimpleDotCom();
        simpleDotCom.setLocation(new int[]{1, 2, 3});
        String guess = "6";
        assertEquals("Miss", simpleDotCom.verifyHit(guess));
    }
    @Test
    public void testNumberOfTries(){
        SimpleDotCom simpleDotCom = new SimpleDotCom();
        simpleDotCom.setLocation(new int[]{1, 2, 3});
        String guess = "4";
        simpleDotCom.verifyHit(guess);
        guess = "2";
        simpleDotCom.verifyHit(guess);
        guess = "1";
        simpleDotCom.verifyHit(guess);
        assertEquals(3,simpleDotCom.numberOfTries);
    }

    @Test
    public void testNumberOfHits(){
        SimpleDotCom simpleDotCom = new SimpleDotCom();
        simpleDotCom.setLocation(new int[]{1, 2, 3});
        String guess = "3";
        simpleDotCom.verifyHit(guess);
        guess = "2";
        simpleDotCom.verifyHit(guess);
        guess = "1";
        simpleDotCom.verifyHit(guess);
        assertEquals(3, simpleDotCom.numberOfHits);
    }
   @Test
   public void testIfDead(){
       SimpleDotCom simpleDotCom = new SimpleDotCom();
       simpleDotCom.setLocation(new int[]{1, 2, 3});
       String guess = "1";
       assertEquals("Hit", simpleDotCom.verifyHit(guess));
       guess = "2";
       assertEquals("Hit", simpleDotCom.verifyHit(guess));
       guess = "3";
       assertEquals("Dead", simpleDotCom.verifyHit(guess));
   }

}
